
/**
 * event listener manager
 */


var events = {};

function on(name, context, callback) {
  var tmp = [context, callback];
  var callbacks = events[name];
  if (Array.isArray(callbacks)) {
    callbacks.push(tmp);
  } else {
    events[name] = [tmp];
  }

}


function remove(name, context) {
  var callbacks = events[name];
  if (Array.isArray(callbacks)) {
    events[name] = callbacks.filter(function (res) {
      return res[0] != self;
    });
  }


}

function notify(name, data) {

  var callbacks = events[name];
  console.log("call++++++++++++++++++");
  if (Array.isArray(callbacks)) {
    console.log("call============");
    callbacks.map(function (item) {
      var context = item[0];
      var callback = item[1];
      console.log("call------------");
      callback.call(context, data);

    });
  }
}


  module.exports = {
    on: on,
    remove: remove,
    notify: notify

  }